import { getStore } from "../../storage/storage"
import { axios } from "../../utils/axios"

// 获取招聘信息列表
export function getJobInfoListApi(parameter){
    return axios({
        url: "/jobInfoManage/getjobInfoList",
        method: 'get',
        params: parameter,
        headers: {
            token: getStore("token")
        },
    })
}

// 得到全部求职者信息和求职者发布的求职信息
export function getAllHunterInfoAndHunterPublishInfo(parameter){
    return axios({
        url: "/jobInfoManage/getAllHunterInfoAndHunterPublishInfo",
        method: 'get',
        params: parameter,
        headers: {
            token: getStore("token")
        },
    })
}

/**
 * 文件流转换 主要代码块，可自定义下载文件名称
 * @param {} data 
 */
export function download (data,titName) {
    if(!data){
      return
    }
    const content = data
    const blob = new Blob([content],{type: "application/vnd.ms-excel"})
    const fileName = titName?titName: '报废卡号.xlsx'
    if ('download' in document.createElement('a')) { // 非IE下载
      const elink = document.createElement('a')
      elink.download = fileName
      elink.style.display = 'none'
      elink.href = URL.createObjectURL(blob)
      document.body.appendChild(elink)
      elink.click()
      URL.revokeObjectURL(elink.href) // 释放URL 对象
      document.body.removeChild(elink)
    } else { // IE10+下载
      navigator.msSaveBlob(blob, fileName)
    }
}

// 获取招聘信息列表
export function getDownload(parameter){
    return axios({
        url: "/down",
        method: 'get',
        params: parameter,
        responseType: 'blob',
        headers: {
            token: getStore("token")
        },
    })
}

// 判断求职用户是否存在
export function checkHunterJobUserIsExist(parameter){
    return axios({
        url: "/jobInfoManage/checkHunterJobUserIsExist",
        method: 'get',
        params: parameter,
        headers: {
            token: getStore("token")
        },
    })
}

// 判断是否为管理员
export function isAdminApi(parameter){
    return axios({
        url: "/jobInfoManage/isAdmin",
        method: 'get',
        params: parameter,
        headers: {
            token: getStore("token")
        },
    })
}

// 添加或修改求职信息
export const editOrAddJobInfoApi = (parameter)=>{
    return axios({
        url: "/jobInfoManage/editOrAddJobInfoApi",
        method: 'post',
        data: parameter,
        headers: {
            token: getStore("token")
        },
    })
}

// 删除求职信息
export const delJobInfoByAid = (parameter)=>{
    return axios({
        url: "/jobInfoManage/delJobInfoByAid",
        method: 'post',
        data: parameter,
        headers: {
            token: getStore("token")
        },
    })
}

//获取被点击用户的信息以及用户的求职信息
export const getUserInfoAndJobInfo = (parameter)=>{
    return axios({
        url: "/jobInfoManage/getUserInfoAndJobInfo",
        method: 'get',
        params: parameter,
        headers: {
            token: getStore("token")
        },
    })
}